// pages/shops/search.js
const app = getApp();

let req = require('../../utils/request.js');
let api = require('../../utils/api.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
    })
    var data = {}, 
        _this = this

    data.seller_id = options.id
    data.flt_start = options.flt_start
    data.flt_end = options.flt_end
    data.flt_date = options.flt_date

    req.request(
      api.getFlightInfoBySeller,
      {method: 'POST', data: data},
      function(res) {
        wx.hideLoading();
        res = res.data
        _this.setData({info: res.result, date: data})
      }
    )
    var date = data.flt_date,
        date_arr = date.split('-'),
        today = date_arr[1] + '月' + date_arr[2] + '日'
    _this.setData({today:today})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var date = new Date(),
        data = {}, 
        y = date.getFullYear(),
        m = date.getMonth() + 1,
        month = (m < 10) ? '0' + m : m,
        d = date.getDate(),
        day = (d < 10) ? '0' + d : d,
        _this = this
    _this.setData({
      date: y + '-' + month + '-' + day,
      month: m,
      day: d
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  selectDate(e) {
    var _this = this,
      val = e.detail.value,
      date = val.split('-'),
      data = {},
      seller = _this.data.date.seller_id,
      start = _this.data.date.flt_start,
      end = _this.data.date.flt_end
      
    wx.showLoading({
      title: '加载中',
    })
    req.request(
      api.getFlightInfoBySeller,
      {method: 'POST', data: {
        seller_id: seller,
        flt_start: start,
        flt_end: end,   
        flt_date: val
      }},
      function(res) {
        wx.hideLoading();
        res = res.data
        
        _this.setData({ info: res.result })
      }
    )
    data['today'] = date[1] + '月' + date[2] + '日';
    _this.setData(data);
  },
  detail(e) {
    var id = e.currentTarget.id
    wx.navigateTo({
      url: '/pages/shops/detail?id=' + id,
    })
  }
})